<?php
namespace app\home\controller;
use app\admin\model\Coursetype;
use app\admin\model\Filess;
use app\admin\model\Jstype;
use app\admin\model\News;
use app\admin\model\Newstype;
use app\admin\model\Text;
use app\admin\model\Video;
use app\home\controller\Base;
use app\admin\controller\Nature;
use app\admin\model\Course;
use app\home\model\User;
use app\home\model\Apply;
use app\home\model\Naturetype;
use app\home\model\Slideshow;
use think\Request;
use think\File;
use think\Session;
class  Set extends Base
{
    public $tid = "";
    public function __construct()
    {
      $this->tid = Session::get("teacher_n")['id'];
    }

  public function index(){
        $user = $this->user_info();
        $data = array(
            "setting" => $this->getAllSetting(),
            "user"=>$user,
            "tid"=>$this->tid,
        );
        return view("index",$data);
    }
    public function updatePwd(Request $request){
        $user = $this->user_info();
        $data = $request->post();
        //检测旧密码是否正确，如果正确这直接修改密码
        $res = User::where(array("name"=>$user['name'],"pwd"=>md5($data['pwd1'])))->find();
        if($res){
            $ress = User::update(array("id"=>$user['id'],"pwd"=>md5($data['pwd2'])));
            if($ress){
                Session::delete("user_infos");
                $this->success("修改密码成功，请重新登陆","Login/logins");
            }else{
                $this->error("修改失败");
            }
        }else{
            $this->error("旧密码错误");
        }
    }
}
